| Conditions | 1 |
| Paths | 1 |
| Total Lines | 104 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('NameForm', function(){ |
||
| 5 | |||
| 6 | it('Create plain', function(){ |
||
| 7 | var newNameform = new GedcomX.NameForm(), |
||
| 8 | form = GedcomX.NameForm(); |
||
| 9 | assert.instanceOf(newNameform, GedcomX.NameForm, 'An instance of NameForm is not returned when calling the constructor with new.'); |
||
| 10 | assert.instanceOf(form, GedcomX.NameForm, 'An instance of NameForm is not returned when calling the constructor without new.'); |
||
| 11 | }); |
||
| 12 | |||
| 13 | it('Create with JSON', function(){ |
||
| 14 | var nameForm = GedcomX.NameForm({ |
||
| 15 | id: 'nameform', |
||
| 16 | lang: 'en', |
||
| 17 | fullText: 'Jonathan Burrows', |
||
| 18 | parts: [ |
||
| 19 | { |
||
| 20 | type: 'http://gedcomx.org/Given', |
||
| 21 | value: 'Jonathan' |
||
| 22 | }, |
||
| 23 | { |
||
| 24 | type: 'http://gedcomx.org/Surname', |
||
| 25 | value: 'Burrows' |
||
| 26 | } |
||
| 27 | ] |
||
| 28 | }); |
||
| 29 | assert.equal(nameForm.getId(), 'nameform'); |
||
| 30 | assert.equal(nameForm.getLang(), 'en'); |
||
| 31 | assert.equal(nameForm.getFullText(), 'Jonathan Burrows'); |
||
| 32 | assert.equal(nameForm.getParts().length, 2); |
||
| 33 | assert.equal(nameForm.getParts()[0].getType(), 'http://gedcomx.org/Given'); |
||
| 34 | assert.equal(nameForm.getParts()[0].getValue(), 'Jonathan'); |
||
| 35 | assert.equal(nameForm.getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
||
| 36 | assert.equal(nameForm.getParts()[1].getValue(), 'Burrows'); |
||
| 37 | }); |
||
| 38 | |||
| 39 | it('Create with mixed data', function(){ |
||
| 40 | var nameForm = GedcomX.NameForm({ |
||
| 41 | id: 'nameform', |
||
| 42 | lang: 'en', |
||
| 43 | fullText: 'Jonathan Burrows', |
||
| 44 | parts: [ |
||
| 45 | GedcomX.NamePart({ |
||
| 46 | type: 'http://gedcomx.org/Given', |
||
| 47 | value: 'Jonathan' |
||
| 48 | }), |
||
| 49 | GedcomX.NamePart({ |
||
| 50 | type: 'http://gedcomx.org/Surname', |
||
| 51 | value: 'Burrows' |
||
| 52 | }) |
||
| 53 | ] |
||
| 54 | }); |
||
| 55 | assert.equal(nameForm.getId(), 'nameform'); |
||
| 56 | assert.equal(nameForm.getLang(), 'en'); |
||
| 57 | assert.equal(nameForm.getFullText(), 'Jonathan Burrows'); |
||
| 58 | assert.equal(nameForm.getParts().length, 2); |
||
| 59 | assert.equal(nameForm.getParts()[0].getType(), 'http://gedcomx.org/Given'); |
||
| 60 | assert.equal(nameForm.getParts()[0].getValue(), 'Jonathan'); |
||
| 61 | assert.equal(nameForm.getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
||
| 62 | assert.equal(nameForm.getParts()[1].getValue(), 'Burrows'); |
||
| 63 | }); |
||
| 64 | |||
| 65 | it('Build', function(){ |
||
| 66 | var nameForm = new GedcomX.NameForm() |
||
| 67 | .setId('nameform') |
||
| 68 | .setLang('en') |
||
| 69 | .setFullText('Jonathan Burrows') |
||
| 70 | .addPart(GedcomX.NamePart().setType('http://gedcomx.org/Given').setValue('Jonathan')) |
||
| 71 | .addPart(GedcomX.NamePart().setType('http://gedcomx.org/Surname').setValue('Burrows')); |
||
| 72 | assert.equal(nameForm.getId(), 'nameform'); |
||
| 73 | assert.equal(nameForm.getLang(), 'en'); |
||
| 74 | assert.equal(nameForm.getFullText(), 'Jonathan Burrows'); |
||
| 75 | assert.equal(nameForm.getParts().length, 2); |
||
| 76 | assert.equal(nameForm.getParts()[0].getType(), 'http://gedcomx.org/Given'); |
||
| 77 | assert.equal(nameForm.getParts()[0].getValue(), 'Jonathan'); |
||
| 78 | assert.equal(nameForm.getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
||
| 79 | assert.equal(nameForm.getParts()[1].getValue(), 'Burrows'); |
||
| 80 | }); |
||
| 81 | |||
| 82 | it('toJSON', function(){ |
||
| 83 | var data = { |
||
| 84 | id: 'nameform', |
||
| 85 | lang: 'en', |
||
| 86 | fullText: 'Jonathan Burrows', |
||
| 87 | parts: [ |
||
| 88 | { |
||
| 89 | type: 'http://gedcomx.org/Given', |
||
| 90 | value: 'Jonathan' |
||
| 91 | }, |
||
| 92 | { |
||
| 93 | type: 'http://gedcomx.org/Surname', |
||
| 94 | value: 'Burrows' |
||
| 95 | } |
||
| 96 | ] |
||
| 97 | }, nameForm = GedcomX.NameForm(data); |
||
| 98 | assert.deepEqual(nameForm.toJSON(), data); |
||
| 99 | }); |
||
| 100 | |||
| 101 | it('constructor does not copy instances', function(){ |
||
| 102 | var obj1 = GedcomX.NameForm(); |
||
| 103 | var obj2 = GedcomX.NameForm(obj1); |
||
| 104 | assert.strictEqual(obj1, obj2); |
||
| 105 | }); |
||
| 106 | |||
| 107 | }); |